package pantallas;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import control.*;
public class PantallaPrincipal implements ActionListener, WindowListener{

/************atributos*******************************************/
    private ManejadorPrincipal mp;
    public JFrame ventanaPrincipal;
/*****************************************************************/

/************metodos**********************************************/
    public PantallaPrincipal() {}
    public PantallaPrincipal(ManejadorPrincipal mp) {
        this.mp = mp;
        crearPantalla();
        mostrarPantalla();
    }

    public void crearPantalla(){
        ventanaPrincipal = new JFrame("El Juego");
        ventanaPrincipal.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        ventanaPrincipal.setBounds(100, 100, 200, 300);
        ventanaPrincipal.getContentPane().setLayout(null);
        ventanaPrincipal.addWindowListener((WindowListener)this);

        JLabel titulo = new JLabel("Menu Principal");
        titulo.setBounds(15, 10, 100, 20);
        titulo.setPreferredSize(new Dimension(100, 30));
        ventanaPrincipal.getContentPane().add(titulo);

        JButton botonCrear = new JButton("Crear Partida");
        botonCrear.setBounds(15, 100, 160, 20);
        ventanaPrincipal.getContentPane().add(botonCrear);
        botonCrear.setMnemonic(KeyEvent.VK_C);/*Dice que apretando la C se pulsa el boton*/
        botonCrear.setActionCommand("crear");
        botonCrear.addActionListener(this);

        JButton botonUnirse = new JButton("Unirse a Partida");
        botonUnirse.setBounds(15, 130, 160, 20);
        ventanaPrincipal.getContentPane().add(botonUnirse);
        botonUnirse.setMnemonic(KeyEvent.VK_U);
        botonUnirse.setActionCommand("unirse");
        botonUnirse.addActionListener(this);

        JButton botonVolver = new JButton("Salir");
        botonVolver.setBounds(15, 160, 160, 20);
        ventanaPrincipal.getContentPane().add(botonVolver);
        botonVolver.setMnemonic(KeyEvent.VK_S);
        botonVolver.setActionCommand("salir");
        botonVolver.addActionListener(this);
    }
    public void mostrarPantalla(){
        ventanaPrincipal.setVisible(true);
    }
    public void ocultarPantalla(){
        ventanaPrincipal.setVisible(false);
    }
    public void actionPerformed(ActionEvent e) {
        if ("crear".equals(e.getActionCommand())) {
           // ventanaPrincipal.setVisible(false);
            mp.ejecutarManejadorCrearPartida();
         }
         if ("unirse".equals(e.getActionCommand())){
            ventanaPrincipal.setVisible(false);
            mp.ejecutarManejadorUnirsePartida();
         }
         if ("salir".equals(e.getActionCommand())){
            ventanaPrincipal.setVisible(false);
            mp.salir();
         }
    }

  public void windowClosing(WindowEvent e) { mp.salir(); }
  public void windowClosed(WindowEvent e) { mp.salir(); }
  public void windowOpened(WindowEvent e) { }
  public void windowIconified(WindowEvent e) { }
  public void windowDeiconified(WindowEvent e) { }
  public void windowActivated(WindowEvent e) { }
  public void windowDeactivated(WindowEvent e) { }
/*****************************************************************/
}